package cn.mumzone.pos.ui.adapter.warehouse;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

import cn.mumzone.basic.adapter.rv.ItemViewDelegate;
import cn.mumzone.basic.adapter.rv.ViewHolder;
import cn.mumzone.basic.util.StringUtils;
import cn.mumzone.pos.AppConstants;
import cn.mumzone.pos.R;
import cn.mumzone.pos.model.WarehouseDetailEntity;

/**
 * Created By Dlx
 * on 2019/10/10
 */
public class ItemView_LongWarehouseDetail implements ItemViewDelegate<WarehouseDetailEntity.GoodsListBean> {
    private String inType;

    //    public ItemView_LongWarehouseDetail(String inType) {
//        this.inType = inType;
//    }
    public void setInType(String inType) {
        this.inType = inType;
    }

    @Override
    public int getItemViewLayoutId() {
        return R.layout.item_warehouse_long;
    }

    @Override
    public boolean isForViewType(WarehouseDetailEntity.GoodsListBean item, int position) {
        //todo 有批次时返回true
        return 1 == item.getIsBatch();
    }

    @Override
    public void convert(ViewHolder holder, WarehouseDetailEntity.GoodsListBean entity, int position) {


        LinearLayout view = (LinearLayout) holder.getView(R.id.ll_root);
        List<WarehouseDetailEntity.GoodsListBean.GoodsBatchNumListBean> list = entity.getGoodsBatchNumList();

        holder.setText(R.id.tv_good_name, entity.getGoodsName());
        holder.setText(R.id.tv_good_unit, StringUtils.isEmpty(entity.getGoodsSpec()) ? "无" : entity.getGoodsSpec());

        for (WarehouseDetailEntity.GoodsListBean.GoodsBatchNumListBean bean : list) {
            View batchView = LayoutInflater.from(holder.getConvertView().getContext())
                    .inflate(R.layout.item_warehouse_long_item, view, false);

            TextView tvDate = batchView.findViewById(R.id.tv_good_date);
            TextView tvBatch = batchView.findViewById(R.id.tv_good_batch);
            TextView tvNum = batchView.findViewById(R.id.tv_good_num);

            if (AppConstants.WAREHOUSE_OTHER.equals(inType)) {
                LinearLayout llPrice = batchView.findViewById(R.id.ll_price);
                llPrice.setVisibility(View.VISIBLE);
                TextView tvPrice = batchView.findViewById(R.id.tv_good_price);
                tvPrice.setText("￥" + bean.getGoodsPrice());
            }


            tvDate.setText(bean.getDateInProduced());
            tvBatch.setText(bean.getGoodsBatchNumber());
            tvNum.setText(bean.getGoodsNum() + bean.getGoodsUnit());

            view.addView(batchView);
        }
    }
}
